package com.example.sync.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.sync.mapper.SysASyncJobMapper;
import com.example.sync.po.SysASyncJob;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author chentao
 * @version 1.0
 * @description: TODO
 * @date 2025/3/22 下午1:40
 */
@Service
public class SysASyncJobServiceImpl extends ServiceImpl<SysASyncJobMapper, SysASyncJob> implements SysASyncJobService {

    /***
     * 获取待执行的任务列表
     * @param serverKey
     * @param maxSize
     * @param maxRetryCount
     * @return
     */
    @Override
    public List<SysASyncJob> getSysASyncJob(Long serverKey, int maxSize, int maxRetryCount) {
        return getBaseMapper().getSysASyncJob(serverKey, maxSize, maxRetryCount);
    }

    /***
     * 分片把任务做转移
     * @param sourceServerId
     * @param targetServerId
     * @param index
     * @param total
     */
    @Override
    public void updateASyncJobServerBatch(Long sourceServerId, Long targetServerId, int index, int total) {
        getBaseMapper().updateASyncJobServerBatch(sourceServerId, targetServerId, index, total);
    }

    /***
     * 主节点分配任务
     * @param targetServerKey
     * @param countSize
     */
    @Override
    public void updateASyncServer(Long targetServerKey, int countSize) {
        getBaseMapper().updateASyncServer(targetServerKey, countSize);
    }
}
